<?php
if (!defined('IN_XLP')) {
    exit('Access Denied');
}
$Document = array(
    'pageid' => 'access-add', //页面标示
    'pagename' => '添加访问控制', //当前页面名称
    'mycss' => array(), //加载的css样式表
    'myjs' => array(), //加载的js脚本
	'footerjs'=>array(),
    'head' => true, //加载头部文件
);
include getTpl('header', 'public');
?>
<!--顶部导航 开始-->
<?php include getTpl('top', 'public');?>
<!--顶部导航 结束-->
<!--左侧菜单 开始-->
<?php include getTpl('nav', 'public');?>
<!--左侧菜单 结束-->
<!--主体 开始-->
<section id="content">
  <section class="main padder">
    <div class="clearfix">
      <h4><i class="fa fa-edit"></i><?php echo trim($Document['pagename'],'_');?></h4>
    </div>
    <div class="row">
      <div class="col-sm-12">
        <section class="panel">
          <div class="panel-body">
            <form class="form-horizontal" method="post" id="Form1">
            <div class="form-group">
                <label class="col-sm-1 control-label">帐号组别</label>
                <div class="col-lg-2">
                  <select name="groupid" id="groupid" class="form-control">
                   <?php
				   foreach($group as $key=>$val){
				   ?>
                    <option value="<?php echo $key;?>"><?php echo $val;?></option>
                    <?php
				   }
				   ?>
                  </select>
                </div>
              </div>
              
              <div class="form-group">
                <label class="col-sm-1 control-label">节点组别</label>
                <div class="col-lg-2">
                  <select name="n_group" id="n_group" class="form-control">
                  <option value="">选择分组</option>
                   <?php
				   foreach($rs as $val){
				   ?>
                    <option value="<?php echo $val['n_group'];?>"><?php echo $val['c_group'].'['.$val['n_group'].']';?></option>
                    <?php
				   }
				   ?>
                  </select>
                </div>
              </div>
              
              <div class="form-group">
                <label class="col-sm-1 control-label">节点控制器</label>
                <div class="col-lg-2">
                  <select name="n_action" id="n_action" class="form-control">
                  <option value="">选择先选择分组</option>
                  </select>
                </div>
              </div>
<style>
.checkbox-lab{margin:5px}
</style>
              <div id="show-detail-list"></div>

              <div class="form-group">
                <div class="col-sm-9 col-lg-offset-1">
                  <div class="col-sm-1">
                    <button type="submit" id="sub-ok" data-loading-text="正在提交..." class="btn btn-primary">保存</button>
                  </div>
                  <div class="col-md-offset-2">
                    <button type="button" class="btn btn-white">取消</button>
                  </div>
                </div>
              </div>
            </form>
          </div>
        </section>
      </div>
    </div>
  </section>
</section>
<!--主体 结束--> 
<script>
$(function(){
	$('#Form1').submit(function(){
		var groupid=$.trim($("#groupid").val());
		var n_group=$.trim($("#n_group").val());
		var n_action=$.trim($("#n_action").val());
		if (!groupid){
			Msg.error('请选择用户组');
			resetSubmit("#sub-ok",'保存');
			return false;
		}
		if (!n_group){
			Msg.error('请选择控制分组');
			resetSubmit("#sub-ok",'保存');
			return false;
		}
		if (!n_action){
			Msg.error('请选择控制器');
			resetSubmit("#sub-ok",'保存');
			return false;
		}
		Msg.loading();
		  $.post('<?php echo U('access/set_access');?>',$(this).serialize(),function(result){
			  Msg.hide();
			  resetSubmit("#sub-ok",'保存');
			  if (result.status==1){
				Msg.ok('添加成功',function(){
					document.location='<?php echo U('access/list_access');?>';	
				},1000);  
			}else{
				Msg.error(result.info);
			}
		  },'json');
		return false;
	})
	$("#n_group").change(function(){
		var val=$(this).val();
		if (!val){
			$("#n_action").html('<option value="">选择先选择分组</option>');
			$("#show-detail-list").html('');
		}else{
			Msg.loading();
		$.getJSON('<?php echo U('access/get_access_list');?>',{"st":'n_group',"q":val},function(result){
			  Msg.hide();
			  if (result.status==1){
				var html='<option value="">选择先选择控制器</option>';
				var val=null;
				for(i in result.data){
					val=result.data[i];
					html+='<option value="'+val.n_action+'">'+val.c_action+'['+val.n_action+']</option>';
				}
				$("#n_action").html(html); 
			}else{
				Msg.error(result.info);
			}
		  });
		}
	});
	$("#n_action").change(function(){
		var val=$(this).val();
		if (!val){
			$("#show-detail-list").html('');
		}else{
			Msg.loading();
		$.getJSON('<?php echo U('access/get_access_list');?>',{"st":'n_action',"q":val},function(result){
			  Msg.hide();
			  if (result.status==1){
				$("#show-detail-list").html(result.data); 
			}else{
				Msg.error(result.info);
			}
		  });
		}
	});

})
</script>
<?php
include getTpl('footer', 'public');
?>